Insert a string in the middle¶
S[:2] + word + S[2:]
Write a python function to insert a string in the middle of a string.
Sample function and result :
insert_sting_middle(‘[[]]’, ‘Python’) -> [[Python]]
insert_sting_middle(‘{{}}’, ‘PHP’) -> {{PHP}}
insert_sting_middle(‘<<>>’, ‘HTML’) -> <<HTML>>
def insert_sting_middle(S, word):
return S[:2] + word + S[2:]
# test
print(insert_sting_middle('[[]]', 'Python')) # [[Python]]
print(insert_sting_middle('{{}}', 'PHP')) # {{PHP}}
print(insert_sting_middle('<<>>', 'HTML')) # <<HTML>>